classdef ziPlotterDataArray < handle
    %ZIPLOTTERDATAARRAY Summary of this class goes here
    %   Detailed explanation goes here
    
    properties
        dataArray
        offset
    end
    
    methods
        function obj = ziPlotterDataArray(dataArray)
            %ZIPLOTTERDATAARRAY Construct an instance of this class
            %   Detailed explanation goes here
            obj.dataArray = arrayfun(@(x) EquipmentControl.ZI.ziData.ziPlotterData( x ), dataArray);
%             obj.offset = obj.dataArray(1).get_fisrt_timestamp();
        end
%%        
        function disp(obj)
            nSegment = length(obj.dataArray);
            fprintf('ziPlotterDataArray has %d segments.\n', nSegment);
            if nSegment >= 1
                obj.dataArray(1).disp;
            end
        end
        function data = getNodeData(obj, chIdx, nodeName)
            data_array = arrayfun(@(d) d.getNodeData(chIdx, nodeName, 'KeepOffset', true), obj.dataArray);
            timeArray = cat(1, data_array.time);
            data.time = timeArray-timeArray(1);
            data.value = cat(1, data_array.value);
            data.label = nodeName;
        end
        function p = plotNodeData(obj, chIdx, nodeName)
            data = obj.getNodeData(chIdx, nodeName);
            p=plot(data.time, data.value, 'DisplayName', data.label);
        end
%% deprecated        
%         function res = getSingleArray(obj, idx, varargin)
%             res1 = obj.dataArray( idx(1) ).getArray(varargin{:});
%             res.label = res1.label;
%             res.x=[]; res.y=[];
%             for k = 1:length(idx)
%                 res_k = obj.dataArray( idx(k) ).getArray('offset', obj.offset, varargin{:});
%                 res.x = [res.x res_k.x];
%                 res.y = [res.y res_k.y];
%             end
%         end
%         function res = getSingleArray_R(obj, idx, varargin)
%             res.label = {'r'};
%             res.x=[]; res.y=[];
%             for k = 1:length(idx)
%                 res_k = obj.dataArray( idx(k) ).getArray_R('offset', obj.offset, varargin{:});
%                 res.x = [res.x res_k.x];
%                 res.y = [res.y res_k.y];
%             end
%         end
% 
%         function res = getArray(obj, varargin)
%             res1 = obj.dataArray(1).getArray(varargin{:});
%             
%             res.label = res1.label;
%             res.x = [];
%             res.y = [];
%             for k=1:length(obj.dataArray)
%                 res_k = obj.dataArray(k).getArray('offset', obj.offset, varargin{:});
%                 res.x = [res.x res_k.x];
%                 res.y = [res.y res_k.y];
%             end
%         end
%         
%         function res = getArray_R(obj, varargin)
%             p=inputParser;
%             p.addParameter('component', {});
%             p.addParameter('node_index', 1);
%             p.addParameter('offset', obj.offset);
%             p.parse(varargin{:});
%             
%             dmodXY = obj.getArray('component', {'x', 'y'}, 'node_index', p.Results.node_index, 'offset', p.Results.offset);
%             
%             res.label = {'r'};
%             res.x = dmodXY.x;
%             res.y = sqrt(sum(dmodXY.y.^2, 1));
%         end
%         
%         function showData(obj, varargin)
%             res = obj.getArray(varargin{:});
%             figure;plot(res.x, res.y);
%             legend(res.label);
%         end
        
    end
end

